package cn.tedu.scheduled;

import org.springframework.context.annotation.Scope;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class SpringScheduledTasks {

    @Scheduled(fixedRate = 1000)
    public void fixedRateTask(){
        String threadName=Thread.currentThread().getName();
        System.out.println(threadName+"->fixedRateTask:"+System.currentTimeMillis());
    }
    @Scheduled(fixedDelay = 1000)
    public void fixedDelayTask() throws InterruptedException {
        String threadName=Thread.currentThread().getName();
        System.out.println(threadName+"->fixedDelayTask:"+System.currentTimeMillis());
        //Thread.sleep(2000);
    }
    //cron表达式应用
    //语法：{秒}{分钟}{小时}{日}{月}{周}{年}
    //对于此表达式，暂时不需要精通，了解即可
    @Scheduled(cron = "*/5 * * * * *")
    public void fixedRateCronTask() throws InterruptedException {
        String threadName=Thread.currentThread().getName();
        System.out.println(threadName+"->fixedRateCronTask:"+System.currentTimeMillis());
    }
}
